package handler

import (
	"github.com/gin-gonic/gin"
	"repo-adder/model"
)

func Add(c *gin.Context) {
	repo_code := c.PostForm("repo_code")
	repo_name := c.PostForm("repo_name")
	address := c.PostForm("address")
	if repo_code == "" || repo_name == "" || address == "" {
		c.JSON(200, gin.H{"code": 500, "msg": "数据不能为空"})
		return
	}
	repo := model.Repo{
		RepoCode: repo_code,
		RepoName: repo_name,
		Address:  address,
	}
	err := model.DB.Create(&repo).Error
	if err != nil {
		c.JSON(200, gin.H{"code": 500, "msg": "添加失败"})
		return
	}
	c.JSON(200, gin.H{"code": 200, "msg": "添加成功"})
	return
}
